package com.zhyl.demo.controller;

import com.zhyl.demo.entity.Consultation;
import com.zhyl.demo.service.ConsultationService;
import com.zhyl.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yang3
 */
@RestController
@RequestMapping("/consultation")
public class ConsultationController {
    private final ConsultationService consultationService;
    @Autowired
    private ConsultationController(ConsultationService consultationService){
        this.consultationService = consultationService;
    }

    @PostMapping("/addConsultation")
    public Result addConsultation(@RequestBody Consultation consultation){
        if (consultation.getConsultName()==null)
        {
            return Result.error("参数错误");
        }
        Boolean aBoolean = consultationService.addConsultation(consultation);
        if (aBoolean){
            int consultationId = consultation.getId();
            return Result.success(consultationId);
        }else {
            return Result.error("添加失败");
        }
    }
}
